import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:untitled/home/home.dart';
import 'package:untitled/mine/mine.dart';


// import 'package:xichong/other/evaluate_page.dart';
//路由表管理
class JRoutes {
  static const String home = "/";
  static const String mine = "mine";
  //初始化路由列表
  static Map<String, WidgetBuilder> routes = {
    home: (context) => Home(),
    mine: (context) => Mine(),
  };

  static Route? routeGenerator(RouteSettings settings) {
    final String? name = settings.name;
    print("routeGenerator");
    final Function pageBuilder = routes[name]!;
    if (settings.arguments != null) {
      //如果路由时传递了参数
      return MaterialPageRoute(
          builder: (context) => pageBuilder(context, settings.arguments));
    } else {
      //没有传递参数
      return MaterialPageRoute(builder: (context) => pageBuilder(context));
    }
  }

  //跳转页面
  static dynamic skipToPage(BuildContext context, String pageName,
      [Map<String, dynamic>? arguments]) {
    if (arguments != null) {
      Navigator.of(context).pushNamed(pageName, arguments: arguments);
    } else {
      Navigator.of(context).pushNamed(pageName);
    }
  }

  //跳转页面，并杀死其他页面
  static void skipToPageAndKillOther(BuildContext context, String pageName) {
    Navigator.of(context).popUntil(ModalRoute.withName(pageName));
  }

  //替换，代表当前页会被销毁
  static void replacePage(BuildContext context, String pageName) {
    Navigator.of(context).pushReplacementNamed(pageName);
  }
}
